/**
 * @author scylla
 * @version V1.0
 * @Project echo-java-base
 * @Title 内部线程2
 * @Description *
 * @Package concurrent.mthread.self
 * @Since 2021/7/29 1:16 下午
 */
package concurrent.mthread.self;

public class InnerThread2 {

    private int countDown = 5;
    private Thread t;

    /**
     * 直接在构造中实例化线程逻辑
     *
     * @param name
     */
    public InnerThread2(String name) {
        t = new Thread(name) {
            @Override
            public void run() {
                try {
                    for (; ; ) {
                        System.out.println(this);
                        if (--countDown == 0) return;
                        sleep(10);
                    }
                } catch (InterruptedException e) {
                    System.err.println(e.getMessage());
                }
            }

            @Override
            public String toString() {
                return getName() + ": " + countDown;
            }
        };

        //启动
        t.start();
    }


}
